<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends Controller {   
    //显示首页
    public function index(){
        
     $category=M('category');
     $catelist=$category->where('pid=0')->select();
    
     foreach ($catelist as $k=>$v)//对一级分类循环
     {
         $catelist[$k]['child']=fenlei($v['cid']);
     }
     $this->assign("catelist",$catelist);
     
     $best=M('goods');
     $bestlist=$best->where("is_best='yes' and recycle='no'")->limit(4)->select();
      $this->assign("bestlist",$bestlist);
      
      $this->display();
  }
 //显示商品的详细信息
     public function goods(){
         $gid=I("get.gid",0);
         $goods=M(goods);
         $goodsrow=$goods->where("gid=$gid")->find();//获取一条
         
         $cid=$goodsrow['cid'];
         
         //获得商品的属性
         $attr=D("GoodsAttr")->getData($cid,$gid);
                 
         $types=D("Category")->getPidList($cid);
         
         $this->assign("types",$types);
         $this->assign("goodsrow",$goodsrow);   
         $this->assign("attr",$attr);         
          $this->display();
     }
     public function find(){
         //获取参数
         $cid=I('get.cid',0);
         //查询cid的分类名称
         $cname=M('category')->where("cid=$cid")->getField('cname');
        
         $gdata=D('Goods')->getByFilter(
                 'gid,gname,price,thumb',
                array('cid'=>$cid)
                 );
          $this->assign("gdata",$gdata);
         $this->assign("cname",$cname);
         $this->display();
     }
   }
